package message;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import resoft.xlink.core.Message;
import util.Config;

public class TestMessage9121 {

	private static Connection conn = null;

	public void doMsgInfo(Message returnMsg) throws ClassNotFoundException,
			SQLException {
		Config.load("../conf/tmis.properties");
		Class.forName(Config.FORNAME);
		conn = DriverManager.getConnection(Config.DBURL, Config.USERNAME,
				Config.PASSWORD);
		conn.setAutoCommit(false);
		Statement stmt = conn.createStatement();

		String workdate = returnMsg
				.getString("//CFX/MSG/MsgReturn9121/OriEntrustDate");
		String oriMsgNo = returnMsg
				.getString("//CFX/MSG/MsgReturn9121/OriMsgNo");
		String oriRequestNo = returnMsg
				.getString("//CFX/MSG/MsgReturn9121/OriRequestNo");
		String result = returnMsg.getString("//CFX/MSG/MsgReturn9121/Result");
		String addWord = returnMsg.getString("//CFX/MSG/MsgReturn9121/AddWord");

		String sql = null;

		if ("2170".equals(oriMsgNo)) {
			sql = "update sendpbochead2170 set remark='" + result
					+ "',addword='" + addWord + "' where packno='"
					+ oriRequestNo + "' and workdate='" + workdate + "'";
		} else if ("2160".equals(oriMsgNo)) {
			String sqll = "select orichkdate from sendpbocreturn2160 where oridatadate='"
					+ workdate + "' and oripackno='" + oriRequestNo + "'";
			Statement stmtt = conn.createStatement();
			ResultSet rs = stmtt.executeQuery(sqll);
			String orichkdate = null;
			while (rs.next()) {
				orichkdate = rs.getString("orichkdate");
			}
			sql = "update sendpbocreturn2160 set remark1='" + result
					+ "',remark='" + addWord + "' where orichkdate='"
					+ orichkdate + "'";
		} else {
			sql = "update sendpbocall set remark='" + result + "',addword='"
					+ addWord + "' where transtype='" + oriMsgNo
					+ "' and packno='" + oriRequestNo + "'";
		}
		stmt.execute(sql);
		conn.commit();
		conn.close();
	}
}
